Rendering and displaying three dimensional (3-D) graphics typically involves many calculations and computations. For example, to render a 3-D object, a set of coordinate points or vertices that define the object to be rendered is formed. Vertices can be joined to form polygons that define the surface of the object to be rendered and displayed. Once the vertices that define an object are formed, the vertices can be transformed from an object or model frame of reference to a world frame of reference and finally to two dimensional (2-D) coordinates that can be displayed on a flat display device, such as a monitor. Along the way, vertices may be rotated, scaled, eliminated or clipped because they fall outside of a viewable area, lit by various lighting schemes and sources, colorized, otherwise transformed, shaded and so forth. The processes involved in rendering and displaying a 3-D object can be computationally intensive and may involve a large number of vertices.
Complex 3-D objects, or portions thereof, can be represented by collections of triangles (“a mesh”) representing the approximate geometry of the 3-D object, or by a geometry map, or surface, in 2-D surface space. The mesh can be specified through the position of the vertices of the triangles. One or more texture maps can be mapped to the surface to create a textured surface according to a texture mapping process. In this regard, signals textured over a surface can be very general, and can specify any sort of intermediate result that can be input to transformation mechanism(s), such as shader procedure(s), to produce a final color and/or other values associated with a point sample.
The computer graphics industry and graphics pipelines have seen a particularly tremendous amount of growth in the last few years. For example, current generations of computer games are moving to 3-D graphics in an ever increasing and more realistic fashion. At the same time, the speed of play is driven faster and faster. This combination has fueled a genuine need for the rapid rendering of 3-D graphics in relatively inexpensive systems.
The rendering of graphics data in a computer system is a collection of resource intensive processes. The process of shading, i.e., the process of performing complex algorithms upon set(s) of specialized graphics data structures, used to determine values for certain primitives, such as color, etc. associated with the graphics data structures, exemplifies such a computation intensive and complex process. Vertex shaders and pixel shaders are examples of such shaders.
Vertex and pixel shaders are computer programs that run on a specialized computer processor known as a graphics processing unit (“GPU”). The GPU is typically introduced into a general purpose computer system on a specialized piece of graphics hardware often with its own memory. An instance of a vertex or pixel shader is executed by the GPU, often in parallel, for every vertex or pixel in a specified 3-D mesh being displayed. Shaders are typically written in either the native assembly language of the particular GPU or in a high-level shader language, for example.
Shaders typically operate on stream data. The stream data comes from either a rasterization unit or a vertex stream unit on the GPU. In addition, shaders also receive input data from the host CPU known as constants. For a given execution of a set of meshes, these constants are unchanging. Shaders are typically authored with instructions which operate only on these constants, thereby causing each instance of the shader program executing on the GPU to generate intermediate values which are identical across all instances of the shader. The GPU's ability to run shaders is limited in comparison to a CPU by the amount of instructions and resources available. Given that an instance of a shader is executed for every vertex or pixel in a specified 3-D mesh being displayed, it is a waste of GPU resources for each instance of a shader to calculate the same identical intermediate values.
Therefore, what is needed are systems and methods for moving the evaluation of constant expressions in shader programs from the GPU to the CPU.